package com.example.springframeworklearning.controller;

import com.example.springframeworklearning.domain.Order;
import com.example.springframeworklearning.service.OrderService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * @author luo
 * @since 2022/9/22 14:30
 */
@RestController
@RequestMapping("/aspect")
@AllArgsConstructor
public class AspectController {

    private final OrderService orderService;

    @GetMapping("/page")
    public List<Order> page(){
        return orderService.page(1,10);
    }

    @GetMapping("/orderList")
    public List<Order> orderList(){
        return orderService.listOrder();
    }

    @GetMapping("/createOrder")
    public Order createOrder(){
        return orderService.createOrder("罗俊华", LocalDateTime.now());
    }

    @GetMapping("/createBatchOrder")
    public Order createBatchOrder(){
        Order order = new Order();
        order.setName("罗俊华");
        Order order2 = new Order();
        order2.setName("高");
        return orderService.createBatchOrder(Arrays.asList(order,order2));
    }


    @DeleteMapping
    public Order deleteOrder(@RequestParam Long id){
        return orderService.deleteOrder(id);
    }
}
